package com.ptt.sqm.activity;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.provider.MediaStore.Images;
import android.provider.MediaStore.Images.Media;
import android.support.v4.view.ViewPager;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SlidingDrawer;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

import com.ptt.sqm.component.ImageAdapter;
import com.ptt.sqm.component.Search;
import com.ptt.sqm.component.SpinnerObject;
import com.ptt.sqm.component.StationAdapter;
import com.ptt.sqm.model.AssessSuggestion5034;
import com.ptt.sqm.model.BusinessSupportInfo;
import com.ptt.sqm.model.BusinessSupportMKIS;
import com.ptt.sqm.model.BusinessSupportSQM;
import com.ptt.sqm.model.BusinessSupportsSQMList;
import com.ptt.sqm.model.ContactImage;
import com.ptt.sqm.model.ContactImageList;
import com.ptt.sqm.model.ContactImageResult;
import com.ptt.sqm.model.ContactInfo;
import com.ptt.sqm.model.ContactInfoList;
import com.ptt.sqm.model.CustomerInfo;
import com.ptt.sqm.model.EquipmentMKIS;
import com.ptt.sqm.model.EquipmentSQM;
import com.ptt.sqm.model.EquipmentTypeList;
import com.ptt.sqm.model.EquipmentsSQMList;
import com.ptt.sqm.model.ListBusinessSupportTypesResponse;
import com.ptt.sqm.model.LocationInfo;
import com.ptt.sqm.model.Station;
import com.ptt.sqm.model.SuggestionImage;
import com.ptt.sqm.model.SuggestionImageList;
import com.ptt.sqm.model.SupplierInfo;
import com.ptt.sqm.model.SupportInfo;
import com.ptt.sqm.model.SupportInfoList;
import com.ptt.sqm.util.AppUtil;
import com.ptt.sqm.util.WebserviceUtil;
import com.ptt.sqm.util.WidgetUtil;
import com.ptt.sqm.ws.AsyncResponse;
import com.ptt.sqm.ws.DecrementCallback;
import com.ptt.sqm.ws.DefaultTask;
import com.ptt.sqm.ws.DownloadCall;
import com.ptt.sqm.ws.UploadCall;
import com.ptt.sqmonmobile.R;

/**
 * A simple {@link Fragment} subclass. Activities that contain this fragment
 * must implement the
 * {@link StationInformationFragment.OnFragmentInteractionListener} interface to
 * handle interaction events. Use the
 * {@link StationInformationFragment#newInstance} factory method to create an
 * instance of this fragment.
 * 
 */
public class StationInformationFragment extends DefaultFragment implements AsyncResponse, DecrementCallback {

	private static StationInformationFragment fragment;

	private OnFragmentInteractionListener mListener;

	// Create Webservice class object
	private DefaultTask mTask = null;

	private DownloadCall downloadCall = null;

	private UploadCall uploadCall = null;

	private static final int CAMERA_COMPLETE = 100;

	private String stationId;

	private CustomerInfo custInfo;

	private LocationInfo locationInfo;

	private BusinessSupportInfo bizSup;

	private Search search;

	private View mProgressView;

	private View mContentView;

	// Contact Info
	private int contactImgCount;

	private Bitmap curImgFile;

	private TableRow headerContactRow;

	private List<ContactInfo> saveContacts;

	private List<String> deleteContacts;

	private List<String> deleteContactImages;

	private View textEntryViewForResult;

	private View mProgContactView;

	private View mContactView;

	// Support Info
	private TableRow headerSupportRow;

	private List<SupportInfo> saveSupports;

	private List<String> deleteSupports;

	private View mProgSupportView;

	private View mSupportView;

	// Supplier Info
	private TableRow headerSupplierRow;

	// Equipment SQM Info
	private TableRow headerEquipmentRow;

	private EquipmentTypeList equipmentTypeList;

	private ListBusinessSupportTypesResponse businessTypeList;

	private List<EquipmentSQM> saveEquipments;

	private List<String> deleteEquipments;

	private View mProgEquipView;

	private View mEquipView;

	// Equipment MKIS Info
	private TableRow headerEquipmentMKISRow;

	// Business SQM Info
	private TableRow headerBusinessRow;

	private List<BusinessSupportSQM> saveBusiness;

	private List<String> deleteBusiness;

	private View mProgBusinessView;

	private View mBusinessView;

	// Business MKIS Info
	private TableRow headerBusinessMKISRow;

	private int cnt;

	private String cameraFileName;

	// TODO: Rename and change types and number of parameters
	public static StationInformationFragment newInstance(int sectionNumber) {
		fragment = new StationInformationFragment();
		Bundle args = new Bundle();
		args.putInt(AppUtil.ARG_SECTION_NUMBER, sectionNumber);
		fragment.setArguments(args);

		return fragment;
	}

	public StationInformationFragment() {
		// Required empty public constructor
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onViewCreated(view, savedInstanceState);

		// Loading...
		mProgressView = view.findViewById(R.id.progress);
		mContentView = view.findViewById(R.id.container);

		// Contact Loading...
		mProgContactView = view.findViewById(R.id.contact_progress);
		mContactView = view.findViewById(R.id.contact_view);

		// Support Loading...
		mProgSupportView = view.findViewById(R.id.support_progress);
		mSupportView = view.findViewById(R.id.support_view);

		// Equip Loading...
		mProgEquipView = view.findViewById(R.id.equipment_progress);
		mEquipView = view.findViewById(R.id.equipment_view);

		// Business Loading...
		mProgBusinessView = view.findViewById(R.id.business_progress);
		mBusinessView = view.findViewById(R.id.business_view);

		// Equipment Types for Spinner
		mTask = new DefaultTask(com, getString(R.string.method_listequipmenttypes));
		mTask.delegate = fragment;
		mTask.execute();

		// Business Support Types for AutoCompleteText
		mTask = new DefaultTask(com, getString(R.string.method_listbusinesssupporttypes));
		mTask.delegate = fragment;
		mTask.execute();

		// No data
		TextView mNoData = (TextView) getView().findViewById(R.id.no_data);
		mNoData.setVisibility(TextView.INVISIBLE);
		final ViewGroup mHasData = (ViewGroup) getView().findViewById(R.id.has_data);
		mHasData.setVisibility(ViewGroup.GONE);

		// Search Sliding
		final SlidingDrawer slide = (SlidingDrawer) view.findViewById(R.id.search_slider);

		final ViewGroup grid = (ViewGroup) slide.findViewById(R.id.content);

		// Top-to-bottom
		grid.setRotation(180);
		grid.setVisibility(LinearLayout.VISIBLE);
		slide.setRotation(180);
		slide.open();

		if (slide.isOpened()) {
			// TODO Auto-generated method stub
			ImageView handle = (ImageView) slide.findViewById(R.id.handle);
			handle.setImageResource(R.drawable.show);

			WidgetUtil.setupSlideOpened(getActivity(), mNoData, slide);
		}

		slide.setOnDrawerCloseListener(new OnDrawerCloseListener() {

			@Override
			public void onDrawerClosed() {
				// TODO Auto-generated method stub
				grid.setVisibility(LinearLayout.INVISIBLE);
				ImageView handle = (ImageView) slide.findViewById(R.id.handle);
				handle.setImageResource(R.drawable.hide);

				WidgetUtil.setupSlideClosed(getActivity(), mHasData);
			}
		});

		slide.setOnDrawerOpenListener(new OnDrawerOpenListener() {

			@Override
			public void onDrawerOpened() {
				// TODO Auto-generated method stub
				ImageView handle = (ImageView) slide.findViewById(R.id.handle);
				handle.setImageResource(R.drawable.show);

				WidgetUtil.setupSlideOpened(getActivity(), mHasData, slide);
			}
		});

		// Search Input
		search = Search.getInstance(getActivity(), getView(), gson, com);
		search.showSearchStation(getActivity(), getView());

		Button searchBtn = (Button) getView().findViewById(R.id.search_btn);
		Button clearBtn = (Button) getView().findViewById(R.id.clear_btn);

		searchBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (isValid()) {
					clearSearchStationData();
					PropertyInfo stationProp = new PropertyInfo();

					stationProp.setName("StationId");
					stationProp.setValue(search.shipToSelected);
					stationProp.setType(String.class);

					slide.close();
					WidgetUtil.showProgress(mContentView, mProgressView, true);

					mTask = new DefaultTask(com, getString(R.string.method_getcustomerinfo));
					mTask.delegate = fragment;
					mTask.execute(stationProp);
				}
			}
		});

		clearBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				clearSearchStation();
			}
		});

		// Contact Info
		final TextView contactPending = (TextView) view.findViewById(R.id.contact_pending);
		Button contactAdd = (Button) view.findViewById(R.id.contact_add);
		Button contactDelete = (Button) view.findViewById(R.id.contact_delete);
		Button contactSave = (Button) view.findViewById(R.id.contact_save);
		Button contactCancel = (Button) view.findViewById(R.id.contact_cancel);
		CheckBox contactAll = (CheckBox) view.findViewById(R.id.contact_check);
		contactAdd.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
				alert.setTitle(getString(R.string.contact_tab));
				LayoutInflater factory = LayoutInflater.from(getActivity());
				textEntryViewForResult = factory.inflate(R.layout.contact_input, null);

				alert.setView(textEntryViewForResult);

				// clear Current Image
				curImgFile = null;

				// get image
				ImageView mCamera = (ImageView) textEntryViewForResult.findViewById(R.id.contact_image_input);
				mCamera.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						AlertDialog.Builder chooser = new AlertDialog.Builder(getActivity());
						chooser.setTitle(getString(R.string.chooser_title));
						LayoutInflater factory = LayoutInflater.from(getActivity());
						View imageEntryView = factory.inflate(R.layout.image_chooser, null);

						ImageView chooseSnap = (ImageView) imageEntryView.findViewById(R.id.snap);
						ImageView chooseGallery = (ImageView) imageEntryView.findViewById(R.id.gallery);

						chooser.setView(imageEntryView);
						final AlertDialog dialog = chooser.create();
						chooseSnap.setOnClickListener(new OnClickListener() {

							@Override
							public void onClick(View arg0) {
								// TODO Auto-generated method stub
								Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
								cameraFileName = UUID.randomUUID().toString() + AppUtil.JPG_TYPE;
								i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(WidgetUtil.getTempFile(getActivity(), cameraFileName)));
								startActivityForResult(i, AppUtil.PICTURE_TAKEN_FROM_CAMERA);
								dialog.dismiss();
							}

						});

						chooseGallery.setOnClickListener(new OnClickListener() {

							@Override
							public void onClick(View arg0) {
								// TODO Auto-generated method stub
								Intent i = new Intent(Intent.ACTION_PICK, Images.Media.EXTERNAL_CONTENT_URI);
								cameraFileName = UUID.randomUUID().toString() + AppUtil.JPG_TYPE;
								startActivityForResult(i, AppUtil.PICTURE_TAKEN_FROM_GALLERY);
								dialog.dismiss();
							}
						});

						dialog.show();
						dialog.getWindow().setLayout(480, ViewGroup.LayoutParams.WRAP_CONTENT);

					}
				});

				alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						contactPending.setVisibility(TextView.VISIBLE);

						EditText mFullname;
						EditText mTel;
						EditText mMobile;
						EditText mFax;
						EditText mEmail;
						ImageView mImage;
						mFullname = (EditText) textEntryViewForResult.findViewById(R.id.contact_fullname_input);
						mTel = (EditText) textEntryViewForResult.findViewById(R.id.contact_tel_input);
						mMobile = (EditText) textEntryViewForResult.findViewById(R.id.contact_mobile_input);
						mFax = (EditText) textEntryViewForResult.findViewById(R.id.contact_fax_input);
						mEmail = (EditText) textEntryViewForResult.findViewById(R.id.contact_email_input);

						TableLayout table = (TableLayout) getView().findViewById(R.id.contact_table);
						// Inflate your row "template" and fill out the
						// fields.
						TableRow row = (TableRow) LayoutInflater.from(StationInformationFragment.this.getActivity()).inflate(R.layout.contact_row, null);
						((TextView) row.findViewById(R.id.contact_seq_value)).setText(String.valueOf(table.getChildCount()));
						((TextView) row.findViewById(R.id.contact_fullname_value)).setText(mFullname.getText().toString());
						((TextView) row.findViewById(R.id.contact_tel_value)).setText(mTel.getText().toString());
						((TextView) row.findViewById(R.id.contact_mobile_value)).setText(mMobile.getText().toString());
						((TextView) row.findViewById(R.id.contact_fax_value)).setText(mFax.getText().toString());
						((TextView) row.findViewById(R.id.contact_email_value)).setText(mEmail.getText().toString());

						if (curImgFile != null) {

							row.setTag(R.id.tag_second, UUID.randomUUID().toString());
							row.setTag(R.id.tag_third, textEntryViewForResult.getTag(R.id.tag_third));
							row.setTag(R.id.tag_fourth, textEntryViewForResult.getTag(R.id.tag_fourth));
							row.setTag(R.id.tag_sixth, textEntryViewForResult.getTag(R.id.tag_sixth));
							row.setTag(R.id.tag_seventh, textEntryViewForResult.getTag(R.id.tag_seventh));

							ImageView contactImage = (ImageView) row.findViewById(R.id.contact_image_value);

							// save SAVE_FILE_NAME
							contactImage.setTag(textEntryViewForResult.getTag(R.id.tag_third));
							contactImage.setImageBitmap(curImgFile);
							contactImage.setOnClickListener(new OnClickListener() {

								@Override
								public void onClick(View arg0) {
									// TODO Auto-generated method stub
									showImageDialog((Bitmap) curImgFile);
								}
							});
						}

						row.setTag(R.id.tag_first, AppUtil.NEW_CONTACT);
						row.setBackgroundColor(getResources().getColor(R.color.sub_bar));
						table.addView(row);
						table.requestLayout();

						return;
					}

				});

				alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						return;
					}
				});

				final AlertDialog dialog = alert.create();
				dialog.show();

				List<View> errors = new ArrayList<View>();
				errors.add((EditText) textEntryViewForResult.findViewById(R.id.contact_fullname_input));
				errors.add((EditText) textEntryViewForResult.findViewById(R.id.contact_tel_input));
				errors.add((EditText) textEntryViewForResult.findViewById(R.id.contact_mobile_input));
				errors.add((EditText) textEntryViewForResult.findViewById(R.id.contact_fax_input));
				errors.add((EditText) textEntryViewForResult.findViewById(R.id.contact_email_input));

				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryViewForResult.findViewById(R.id.contact_fullname_input), dialog, Integer.parseInt(getString(R.string.maxlength)),
					errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryViewForResult.findViewById(R.id.contact_tel_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryViewForResult.findViewById(R.id.contact_mobile_input), dialog, Integer.parseInt(getString(R.string.maxlength)),
					errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryViewForResult.findViewById(R.id.contact_fax_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryViewForResult.findViewById(R.id.contact_email_input), dialog, Integer.parseInt(getString(R.string.maxlength)),
					errors);

				WidgetUtil.validateRequireData(getActivity(), (EditText) textEntryViewForResult.findViewById(R.id.contact_fullname_input), dialog, errors);
				// WidgetUtil.validateNumericData(getActivity(), (EditText)
				// textEntryViewForResult.findViewById(R.id.contact_fullname_input),
				// dialog);

			}
		});

		contactDelete.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				final AlertDialog.Builder cancelConfirm = new AlertDialog.Builder(getActivity());

				cancelConfirm.setTitle(getString(R.string.alert_confirm_delete));
				cancelConfirm.setNegativeButton("Cancel", null);
				cancelConfirm.setPositiveButton("Ok", new AlertDialog.OnClickListener() {
					public void onClick(DialogInterface dialog, int arg1) {
						// TODO Auto-generated method stub
						TableLayout table = (TableLayout) getView().findViewById(R.id.contact_table);
						// Inflate your row "template" and fill out the
						// fields.
						for (int index = 1; index < table.getChildCount(); index++) {
							TableRow row = (TableRow) table.getChildAt(index);
							CheckBox check = (CheckBox) row.findViewById(R.id.contact_check_value);
							if (check.isChecked()) {
								contactPending.setVisibility(TextView.VISIBLE);
								if (!row.getTag(R.id.tag_first).equals(AppUtil.NEW_CONTACT)) {
									deleteContacts.add((String) row.getTag(R.id.tag_first));

									// Delete image on Server
									ImageView contactImage = (ImageView) row.findViewById(R.id.contact_image_value);
									if (contactImage.getTag() != null) {
										deleteContactImages.add((String) contactImage.getTag());
									}
								}

								table.removeView(row);
								index--;
							}
						}

						// set Sorted Index
						for (int index = 1; index < table.getChildCount(); index++) {
							TableRow row = (TableRow) table.getChildAt(index);
							TextView seq = (TextView) row.findViewById(R.id.contact_seq_value);
							seq.setText(String.valueOf(index));
						}

						table.requestLayout();

					}
				});
				cancelConfirm.show();
			}
		});

		contactAll.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				TableLayout table = (TableLayout) getView().findViewById(R.id.contact_table);
				if (arg1) {
					// Inflate your row "template" and fill out the fields.
					for (int index = 1; index < table.getChildCount(); index++) {
						TableRow row = (TableRow) table.getChildAt(index);
						CheckBox check = (CheckBox) row.findViewById(R.id.contact_check_value);
						check.setChecked(true);
					}
				} else {
					// Inflate your row "template" and fill out the fields.
					for (int index = 1; index < table.getChildCount(); index++) {
						TableRow row = (TableRow) table.getChildAt(index);
						CheckBox check = (CheckBox) row.findViewById(R.id.contact_check_value);
						check.setChecked(false);
					}
				}
			}
		});

		contactSave.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				saveContacts();
				contactPending.setVisibility(TextView.GONE);
			}
		});

		contactCancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				AlertDialog.Builder cancelConfirm = new AlertDialog.Builder(getActivity());

				cancelConfirm.setTitle(getString(R.string.alert_confirm_cancel));
				cancelConfirm.setNegativeButton("Cancel", null);
				cancelConfirm.setPositiveButton("Ok", new AlertDialog.OnClickListener() {
					public void onClick(DialogInterface dialog, int arg1) {
						clearContacts();
						showContacts();
						contactPending.setVisibility(TextView.GONE);
					}
				});
				cancelConfirm.show();
			}
		});

		// Support Info
		final TextView supportPending = (TextView) view.findViewById(R.id.support_pending);
		Button supportAdd = (Button) view.findViewById(R.id.support_add);
		Button supportDelete = (Button) view.findViewById(R.id.support_delete);
		Button supportSave = (Button) view.findViewById(R.id.support_save);
		Button supportCancel = (Button) view.findViewById(R.id.support_cancel);
		CheckBox supportAll = (CheckBox) view.findViewById(R.id.support_check);

		supportAdd.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
				alert.setTitle(getString(R.string.support_tab));
				LayoutInflater factory = LayoutInflater.from(getActivity());
				final View textEntryView = factory.inflate(R.layout.support_input, null);

				alert.setView(textEntryView);

				alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						supportPending.setVisibility(TextView.VISIBLE);
						EditText mType;
						EditText mSubType;
						EditText mCollect;
						EditText mCollectCurrent;
						EditText mRemark;

						mType = (EditText) textEntryView.findViewById(R.id.support_type_input);
						mSubType = (EditText) textEntryView.findViewById(R.id.support_sub_type_input);
						mCollect = (EditText) textEntryView.findViewById(R.id.support_collect_input);
						mCollectCurrent = (EditText) textEntryView.findViewById(R.id.support_collect_current_input);
						mRemark = (EditText) textEntryView.findViewById(R.id.support_remark_input);

						TableLayout table = (TableLayout) getView().findViewById(R.id.support_table);
						// Inflate your row "template" and fill out the
						// fields.
						TableRow row = (TableRow) LayoutInflater.from(StationInformationFragment.this.getActivity()).inflate(R.layout.support_row, null);
						((TextView) row.findViewById(R.id.support_seq_value)).setText(String.valueOf(table.getChildCount()));
						((TextView) row.findViewById(R.id.support_type_value)).setText(mType.getText().toString());
						((TextView) row.findViewById(R.id.support_sub_type_value)).setText(mSubType.getText().toString());
						((TextView) row.findViewById(R.id.support_collect_value)).setText(mCollect.getText().toString());
						((TextView) row.findViewById(R.id.support_collect_current_value)).setText(mCollectCurrent.getText().toString());
						((TextView) row.findViewById(R.id.support_remark_value)).setText(mRemark.getText().toString());

						row.setTag(R.id.tag_first, AppUtil.NEW_SUPPORT);
						row.setBackgroundColor(getResources().getColor(R.color.sub_bar));
						table.addView(row);
						table.requestLayout();

						return;
					}

				});

				alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						return;
					}
				});

				final AlertDialog dialog = alert.create();
				dialog.show();

				List<View> errors = new ArrayList<View>();
				errors.add((EditText) textEntryView.findViewById(R.id.support_type_input));
				errors.add((EditText) textEntryView.findViewById(R.id.support_sub_type_input));
				errors.add((EditText) textEntryView.findViewById(R.id.support_collect_input));
				errors.add((EditText) textEntryView.findViewById(R.id.support_collect_current_input));
				errors.add((EditText) textEntryView.findViewById(R.id.support_remark_input));

				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryView.findViewById(R.id.support_type_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryView.findViewById(R.id.support_sub_type_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryView.findViewById(R.id.support_collect_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryView.findViewById(R.id.support_collect_current_input), dialog, Integer.parseInt(getString(R.string.maxlength)),
					errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryView.findViewById(R.id.support_remark_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);

				WidgetUtil.validateRequireData(getActivity(), (EditText) textEntryView.findViewById(R.id.support_type_input), dialog, errors);

				WidgetUtil.validateNumericData(getActivity(), (EditText) textEntryView.findViewById(R.id.support_collect_input), dialog, errors);
				WidgetUtil.validateNumericData(getActivity(), (EditText) textEntryView.findViewById(R.id.support_collect_current_input), dialog, errors);

			}
		});

		supportDelete.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				final AlertDialog.Builder cancelConfirm = new AlertDialog.Builder(getActivity());

				cancelConfirm.setTitle(getString(R.string.alert_confirm_delete));
				cancelConfirm.setNegativeButton("Cancel", null);
				cancelConfirm.setPositiveButton("Ok", new AlertDialog.OnClickListener() {
					public void onClick(DialogInterface dialog, int arg1) {
						// TODO Auto-generated method stub
						TableLayout table = (TableLayout) getView().findViewById(R.id.support_table);
						// Inflate your row "template" and fill out the
						// fields.
						for (int index = 1; index < table.getChildCount(); index++) {
							TableRow row = (TableRow) table.getChildAt(index);
							CheckBox check = (CheckBox) row.findViewById(R.id.support_check_value);
							if (check.isChecked()) {
								supportPending.setVisibility(TextView.VISIBLE);
								if (!row.getTag(R.id.tag_first).equals(AppUtil.NEW_SUPPORT)) {
									deleteSupports.add((String) row.getTag(R.id.tag_first));
								}

								table.removeView(row);
								index--;
							}
						}

						// set Sorted Index
						for (int index = 1; index < table.getChildCount(); index++) {
							TableRow row = (TableRow) table.getChildAt(index);
							TextView seq = (TextView) row.findViewById(R.id.support_seq_value);
							seq.setText(String.valueOf(index));
						}

						table.requestLayout();

					}
				});
				cancelConfirm.show();
			}
		});

		supportAll.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				TableLayout table = (TableLayout) getView().findViewById(R.id.support_table);
				if (arg1) {
					// Inflate your row "template" and fill out the fields.
					for (int index = 1; index < table.getChildCount(); index++) {
						TableRow row = (TableRow) table.getChildAt(index);
						CheckBox check = (CheckBox) row.findViewById(R.id.support_check_value);
						check.setChecked(true);
					}
				} else {
					// Inflate your row "template" and fill out the fields.
					for (int index = 1; index < table.getChildCount(); index++) {
						TableRow row = (TableRow) table.getChildAt(index);
						CheckBox check = (CheckBox) row.findViewById(R.id.support_check_value);
						check.setChecked(false);
					}
				}
			}
		});

		supportSave.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				saveSupports();
				supportPending.setVisibility(TextView.GONE);
			}
		});

		supportCancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				AlertDialog.Builder cancelConfirm = new AlertDialog.Builder(getActivity());

				cancelConfirm.setTitle(getString(R.string.alert_confirm_cancel));
				cancelConfirm.setNegativeButton("Cancel", null);
				cancelConfirm.setPositiveButton("Ok", new AlertDialog.OnClickListener() {
					public void onClick(DialogInterface dialog, int arg1) {
						clearSupports();
						showSupports();
						supportPending.setVisibility(TextView.GONE);
					}
				});
				cancelConfirm.show();
			}
		});

		// Equipment SQM Info
		final TextView equipmentPending = (TextView) view.findViewById(R.id.equipment_pending);
		Button equipmentAdd = (Button) view.findViewById(R.id.equipment_add);
		Button equipmentDelete = (Button) view.findViewById(R.id.equipment_delete);
		Button equipmentSave = (Button) view.findViewById(R.id.equipment_save);
		Button equipmentCancel = (Button) view.findViewById(R.id.equipment_cancel);
		CheckBox equipmentAll = (CheckBox) view.findViewById(R.id.equipment_check);

		equipmentAdd.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
				alert.setTitle(getString(R.string.equipment_tab));
				LayoutInflater factory = LayoutInflater.from(getActivity());
				final View textEntryView = factory.inflate(R.layout.equipment_input, null);

				// Set Category Spinner
				Spinner categorySpinner = (Spinner) textEntryView.findViewById(R.id.equipment_category_input);
				List<String> checkDup = new ArrayList<String>();
				List<SpinnerObject> arr = new ArrayList<SpinnerObject>();
				for (int index = 0; index < equipmentTypeList.EquipmentType.size(); index++) {
					String EQUIPEMENTTYPE_ID = equipmentTypeList.EquipmentType.get(index).EQUIPEMENTTYPE_ID;
					String EQUIPEMENTTYPE = equipmentTypeList.EquipmentType.get(index).EQUIPEMENTTYPE;

					if (!checkDup.contains(EQUIPEMENTTYPE_ID)) {
						arr.add(new SpinnerObject(EQUIPEMENTTYPE, EQUIPEMENTTYPE_ID));
						checkDup.add(EQUIPEMENTTYPE_ID);
					}
				}
				checkDup.clear();
				ArrayAdapter<SpinnerObject> arrAdt = new ArrayAdapter<SpinnerObject>(getActivity(), android.R.layout.simple_spinner_dropdown_item, arr);
				arrAdt.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
				categorySpinner.setAdapter(arrAdt);

				alert.setView(textEntryView);

				alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						equipmentPending.setVisibility(TextView.VISIBLE);

						EditText mType;
						EditText mBrand;
						EditText mGen;
						EditText mSN;
						EditText mCode;
						EditText mPrice;
						EditText mAmoutMa;
						EditText mPriceMa;
						Spinner mCategory;

						mType = (EditText) textEntryView.findViewById(R.id.equipment_type_input);
						mBrand = (EditText) textEntryView.findViewById(R.id.equipment_brand_input);
						mGen = (EditText) textEntryView.findViewById(R.id.equipment_gen_input);
						mSN = (EditText) textEntryView.findViewById(R.id.equipment_sn_input);
						mCode = (EditText) textEntryView.findViewById(R.id.equipment_code_input);
						mPrice = (EditText) textEntryView.findViewById(R.id.equipment_price_input);
						mAmoutMa = (EditText) textEntryView.findViewById(R.id.equipment_amount_ma_input);
						mPriceMa = (EditText) textEntryView.findViewById(R.id.equipment_price_ma_input);
						mCategory = (Spinner) textEntryView.findViewById(R.id.equipment_category_input);

						TableLayout table = (TableLayout) getView().findViewById(R.id.equipmentsqm_table);
						// Inflate your row "template" and fill out the
						// fields.
						TableRow row = (TableRow) LayoutInflater.from(StationInformationFragment.this.getActivity()).inflate(R.layout.equipment_row, null);
						((TextView) row.findViewById(R.id.equipment_seq_value)).setText(String.valueOf(table.getChildCount()));
						((TextView) row.findViewById(R.id.equipment_type_value)).setText(mType.getText().toString());
						((TextView) row.findViewById(R.id.equipment_brand_value)).setText(mBrand.getText().toString());
						((TextView) row.findViewById(R.id.equipment_gen_value)).setText(mGen.getText().toString());
						((TextView) row.findViewById(R.id.equipment_sn_value)).setText(mSN.getText().toString());
						((TextView) row.findViewById(R.id.equipment_code_value)).setText(mCode.getText().toString());
						((TextView) row.findViewById(R.id.equipment_price_value)).setText(mPrice.getText().toString());
						((TextView) row.findViewById(R.id.equipment_amount_ma_value)).setText(mAmoutMa.getText().toString());
						((TextView) row.findViewById(R.id.equipment_price_ma_value)).setText(mPriceMa.getText().toString());
						((TextView) row.findViewById(R.id.equipment_category_value)).setText(((SpinnerObject) mCategory.getSelectedItem()).getName());
						row.setTag(R.id.tag_second, ((SpinnerObject) mCategory.getSelectedItem()).getValue());

						row.setTag(R.id.tag_first, AppUtil.NEW_EQUIPMENTSQM);

						row.setBackgroundColor(getResources().getColor(R.color.sub_bar));
						table.addView(row);
						table.requestLayout();

						return;
					}

				});

				alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						return;
					}
				});

				final AlertDialog dialog = alert.create();
				dialog.show();

				List<View> errors = new ArrayList<View>();
				errors.add((EditText) textEntryView.findViewById(R.id.equipment_type_input));
				errors.add((EditText) textEntryView.findViewById(R.id.equipment_brand_input));
				errors.add((EditText) textEntryView.findViewById(R.id.equipment_gen_input));
				errors.add((EditText) textEntryView.findViewById(R.id.equipment_sn_input));
				errors.add((EditText) textEntryView.findViewById(R.id.equipment_code_input));
				errors.add((EditText) textEntryView.findViewById(R.id.equipment_price_input));
				errors.add((EditText) textEntryView.findViewById(R.id.equipment_amount_ma_input));
				errors.add((EditText) textEntryView.findViewById(R.id.equipment_price_ma_input));

				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryView.findViewById(R.id.equipment_type_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryView.findViewById(R.id.equipment_brand_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryView.findViewById(R.id.equipment_gen_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryView.findViewById(R.id.equipment_sn_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryView.findViewById(R.id.equipment_code_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryView.findViewById(R.id.equipment_price_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryView.findViewById(R.id.equipment_amount_ma_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryView.findViewById(R.id.equipment_price_ma_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);

				WidgetUtil.validateRequireData(getActivity(), (EditText) textEntryView.findViewById(R.id.equipment_type_input), dialog, errors);
				WidgetUtil.validateRequireData(getActivity(), (EditText) textEntryView.findViewById(R.id.equipment_code_input), dialog, errors);

				WidgetUtil.validateNumericData(getActivity(), (EditText) textEntryView.findViewById(R.id.equipment_price_input), dialog, errors);
				WidgetUtil.validateNumericData(getActivity(), (EditText) textEntryView.findViewById(R.id.equipment_amount_ma_input), dialog, errors);
				WidgetUtil.validateNumericData(getActivity(), (EditText) textEntryView.findViewById(R.id.equipment_price_ma_input), dialog, errors);

			}
		});

		equipmentDelete.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				final AlertDialog.Builder cancelConfirm = new AlertDialog.Builder(getActivity());

				cancelConfirm.setTitle(getString(R.string.alert_confirm_delete));
				cancelConfirm.setNegativeButton("Cancel", null);
				cancelConfirm.setPositiveButton("Ok", new AlertDialog.OnClickListener() {

					public void onClick(DialogInterface dialog, int arg1) {
						// TODO Auto-generated method stub
						TableLayout table = (TableLayout) getView().findViewById(R.id.equipmentsqm_table);
						// Inflate your row "template" and fill out the
						// fields.
						for (int index = 1; index < table.getChildCount(); index++) {
							TableRow row = (TableRow) table.getChildAt(index);
							CheckBox check = (CheckBox) row.findViewById(R.id.equipment_check_value);
							if (check.isChecked()) {
								equipmentPending.setVisibility(TextView.VISIBLE);
								if (!row.getTag(R.id.tag_first).equals(AppUtil.NEW_EQUIPMENTSQM)) {
									deleteEquipments.add((String) row.getTag(R.id.tag_first));
								}

								table.removeView(row);
								index--;
							}
						}

						// set Sorted Index
						for (int index = 1; index < table.getChildCount(); index++) {
							TableRow row = (TableRow) table.getChildAt(index);
							TextView seq = (TextView) row.findViewById(R.id.equipment_seq_value);
							seq.setText(String.valueOf(index));
						}

						table.requestLayout();

					}
				});
				cancelConfirm.show();
			}
		});

		equipmentAll.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				TableLayout table = (TableLayout) getView().findViewById(R.id.equipmentsqm_table);
				if (arg1) {
					// Inflate your row "template" and fill out the fields.
					for (int index = 1; index < table.getChildCount(); index++) {
						TableRow row = (TableRow) table.getChildAt(index);
						CheckBox check = (CheckBox) row.findViewById(R.id.equipment_check_value);
						check.setChecked(true);
					}
				} else {
					// Inflate your row "template" and fill out the fields.
					for (int index = 1; index < table.getChildCount(); index++) {
						TableRow row = (TableRow) table.getChildAt(index);
						CheckBox check = (CheckBox) row.findViewById(R.id.equipment_check_value);
						check.setChecked(false);
					}
				}
			}
		});

		equipmentSave.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				saveEquipments();
				equipmentPending.setVisibility(TextView.GONE);
			}
		});

		equipmentCancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				AlertDialog.Builder cancelConfirm = new AlertDialog.Builder(getActivity());

				cancelConfirm.setTitle(getString(R.string.alert_confirm_cancel));
				cancelConfirm.setNegativeButton("Cancel", null);
				cancelConfirm.setPositiveButton("Ok", new AlertDialog.OnClickListener() {
					public void onClick(DialogInterface dialog, int arg1) {
						clearEquipments();
						showEquipments();
						equipmentPending.setVisibility(TextView.GONE);
					}
				});
				cancelConfirm.show();
			}
		});

		// Business Info
		final TextView businessPending = (TextView) view.findViewById(R.id.business_pending);
		Button businessAdd = (Button) view.findViewById(R.id.business_add);
		Button businessDelete = (Button) view.findViewById(R.id.business_delete);
		Button businessSave = (Button) view.findViewById(R.id.business_save);
		Button businessCancel = (Button) view.findViewById(R.id.business_cancel);
		CheckBox businessAll = (CheckBox) view.findViewById(R.id.business_check);

		businessAdd.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
				alert.setTitle(getString(R.string.business_tab));
				LayoutInflater factory = LayoutInflater.from(getActivity());
				final View textEntryView = factory.inflate(R.layout.business_input, null);

				listBusinessSupportTypes(textEntryView);

				alert.setView(textEntryView);

				alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						businessPending.setVisibility(TextView.VISIBLE);
						EditText mType;
						EditText mName;
						EditText mCustName;
						Spinner mStatus;

						mType = (EditText) textEntryView.findViewById(R.id.business_type_input);
						mName = (EditText) textEntryView.findViewById(R.id.business_name_input);
						mCustName = (EditText) textEntryView.findViewById(R.id.business_custname_input);
						mStatus = (Spinner) textEntryView.findViewById(R.id.business_status_input);

						TableLayout table = (TableLayout) getView().findViewById(R.id.businesssqm_table);
						// Inflate your row "template" and fill out the
						// fields.
						TableRow row = (TableRow) LayoutInflater.from(StationInformationFragment.this.getActivity()).inflate(R.layout.business_row, null);
						((TextView) row.findViewById(R.id.business_seq_value)).setText(String.valueOf(table.getChildCount()));
						((TextView) row.findViewById(R.id.business_type_value)).setText(mType.getText().toString());
						((TextView) row.findViewById(R.id.business_name_value)).setText(mName.getText().toString());
						((TextView) row.findViewById(R.id.business_custname_value)).setText(mCustName.getText().toString());
						((TextView) row.findViewById(R.id.business_status_value)).setText(mStatus.getSelectedItem().toString());

						row.setTag(R.id.tag_first, AppUtil.NEW_BUSINESS);
						row.setBackgroundColor(getResources().getColor(R.color.sub_bar));
						table.addView(row);
						table.requestLayout();

						return;
					}

				});

				alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						return;
					}
				});
				final AlertDialog dialog = alert.create();
				dialog.show();

				List<View> errors = new ArrayList<View>();
				errors.add((EditText) textEntryView.findViewById(R.id.business_type_input));
				errors.add((EditText) textEntryView.findViewById(R.id.business_name_input));
				errors.add((EditText) textEntryView.findViewById(R.id.business_custname_input));

				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryView.findViewById(R.id.business_type_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryView.findViewById(R.id.business_name_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);
				WidgetUtil.validateMaxlengthData(getActivity(), (EditText) textEntryView.findViewById(R.id.business_custname_input), dialog, Integer.parseInt(getString(R.string.maxlength)), errors);

				WidgetUtil.validateRequireData(getActivity(), (EditText) textEntryView.findViewById(R.id.business_type_input), dialog, errors);
				WidgetUtil.validateRequireData(getActivity(), (EditText) textEntryView.findViewById(R.id.business_name_input), dialog, errors);

			}
		});

		businessDelete.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				final AlertDialog.Builder cancelConfirm = new AlertDialog.Builder(getActivity());

				cancelConfirm.setTitle(getString(R.string.alert_confirm_delete));
				cancelConfirm.setNegativeButton("Cancel", null);
				cancelConfirm.setPositiveButton("Ok", new AlertDialog.OnClickListener() {
					public void onClick(DialogInterface dialog, int arg1) {
						// TODO Auto-generated method stub
						TableLayout table = (TableLayout) getView().findViewById(R.id.businesssqm_table);
						// Inflate your row "template" and fill out the
						// fields.
						for (int index = 1; index < table.getChildCount(); index++) {
							TableRow row = (TableRow) table.getChildAt(index);
							CheckBox check = (CheckBox) row.findViewById(R.id.business_check_value);
							if (check.isChecked()) {
								businessPending.setVisibility(TextView.VISIBLE);
								if (!row.getTag(R.id.tag_first).equals(AppUtil.NEW_BUSINESS)) {
									deleteBusiness.add((String) row.getTag(R.id.tag_first));
								}

								table.removeView(row);
								index--;
							}
						}

						// set Sorted Index
						for (int index = 1; index < table.getChildCount(); index++) {
							TableRow row = (TableRow) table.getChildAt(index);
							TextView seq = (TextView) row.findViewById(R.id.business_seq_value);
							seq.setText(String.valueOf(index));
						}

						table.requestLayout();

					}
				});
				cancelConfirm.show();
			}
		});

		businessAll.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				TableLayout table = (TableLayout) getView().findViewById(R.id.businesssqm_table);
				if (arg1) {
					// Inflate your row "template" and fill out the fields.
					for (int index = 1; index < table.getChildCount(); index++) {
						TableRow row = (TableRow) table.getChildAt(index);
						CheckBox check = (CheckBox) row.findViewById(R.id.business_check_value);
						check.setChecked(true);
					}
				} else {
					// Inflate your row "template" and fill out the fields.
					for (int index = 1; index < table.getChildCount(); index++) {
						TableRow row = (TableRow) table.getChildAt(index);
						CheckBox check = (CheckBox) row.findViewById(R.id.business_check_value);
						check.setChecked(false);
					}
				}
			}
		});

		businessSave.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				saveBusinesses();
				businessPending.setVisibility(TextView.GONE);
			}
		});

		businessCancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				AlertDialog.Builder cancelConfirm = new AlertDialog.Builder(getActivity());

				cancelConfirm.setTitle(getString(R.string.alert_confirm_cancel));
				cancelConfirm.setNegativeButton("Cancel", null);
				cancelConfirm.setPositiveButton("Ok", new AlertDialog.OnClickListener() {
					public void onClick(DialogInterface dialog, int arg1) {
						clearBusinesses();
						showBusinesses();
						businessPending.setVisibility(TextView.GONE);

					}
				});
				cancelConfirm.show();
			}
		});

		// show/hide customer
		final ImageView mCustBtn = (ImageView) view.findViewById(R.id.cust_showhide);
		final ImageView mContactBtn = (ImageView) view.findViewById(R.id.contact_showhide);
		final ImageView mSupportBtn = (ImageView) view.findViewById(R.id.support_showhide);
		final ImageView mSupplierBtn = (ImageView) view.findViewById(R.id.supplier_showhide);
		final ImageView mLocalBtn = (ImageView) view.findViewById(R.id.local_showhide);
		final ImageView mEquipBtn = (ImageView) view.findViewById(R.id.equipment_showhide);
		final ImageView mInvestBtn = (ImageView) view.findViewById(R.id.invest_showhide);
		final ImageView mBizBtn = (ImageView) view.findViewById(R.id.business_showhide);
		mCustBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ViewGroup mBox = (ViewGroup) getView().findViewById(R.id.cust_box);

				if (mBox.getVisibility() == ViewGroup.VISIBLE) {
					mCustBtn.setImageResource(R.drawable.showbox);
					mBox.setVisibility(ViewGroup.GONE);
				} else {
					mCustBtn.setImageResource(R.drawable.hidebox);

					mBox.setVisibility(ViewGroup.VISIBLE);
				}
			}
		});
		mContactBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ViewGroup mBox = (ViewGroup) getView().findViewById(R.id.contact_box);

				if (mBox.getVisibility() == ViewGroup.VISIBLE) {
					mContactBtn.setImageResource(R.drawable.showbox);
					mBox.setVisibility(ViewGroup.GONE);
				} else {
					mContactBtn.setImageResource(R.drawable.hidebox);

					mBox.setVisibility(ViewGroup.VISIBLE);
				}
			}
		});
		mSupportBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ViewGroup mBox = (ViewGroup) getView().findViewById(R.id.support_box);

				if (mBox.getVisibility() == ViewGroup.VISIBLE) {
					mSupportBtn.setImageResource(R.drawable.showbox);
					mBox.setVisibility(ViewGroup.GONE);
				} else {
					mSupportBtn.setImageResource(R.drawable.hidebox);
					mBox.setVisibility(ViewGroup.VISIBLE);
				}
			}
		});
		mSupplierBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ViewGroup mBox = (ViewGroup) getView().findViewById(R.id.supplier_box);

				if (mBox.getVisibility() == ViewGroup.VISIBLE) {
					mSupplierBtn.setImageResource(R.drawable.showbox);
					mBox.setVisibility(ViewGroup.GONE);
				} else {
					mSupplierBtn.setImageResource(R.drawable.hidebox);

					mBox.setVisibility(ViewGroup.VISIBLE);
				}
			}
		});
		mLocalBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ViewGroup mBox = (ViewGroup) getView().findViewById(R.id.local_box);
				if (mBox.getVisibility() == ViewGroup.VISIBLE) {
					mLocalBtn.setImageResource(R.drawable.showbox);
					mBox.setVisibility(ViewGroup.GONE);
				} else {
					mLocalBtn.setImageResource(R.drawable.hidebox);
					mBox.setVisibility(ViewGroup.VISIBLE);
				}
			}
		});
		mEquipBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ViewGroup mBox = (ViewGroup) getView().findViewById(R.id.equipment_box);

				if (mBox.getVisibility() == ViewGroup.VISIBLE) {
					mEquipBtn.setImageResource(R.drawable.showbox);
					mBox.setVisibility(ViewGroup.GONE);
				} else {
					mEquipBtn.setImageResource(R.drawable.hidebox);

					mBox.setVisibility(ViewGroup.VISIBLE);
				}
			}
		});
		mInvestBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ViewGroup mBox = (ViewGroup) getView().findViewById(R.id.invest_box);

				if (mBox.getVisibility() == ViewGroup.VISIBLE) {
					mInvestBtn.setImageResource(R.drawable.showbox);
					mBox.setVisibility(ViewGroup.GONE);
				} else {
					mInvestBtn.setImageResource(R.drawable.hidebox);

					mBox.setVisibility(ViewGroup.VISIBLE);
				}
			}
		});
		mBizBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ViewGroup mBox = (ViewGroup) getView().findViewById(R.id.business_box);

				if (mBox.getVisibility() == ViewGroup.VISIBLE) {
					mBizBtn.setImageResource(R.drawable.showbox);
					mBox.setVisibility(ViewGroup.GONE);
				} else {
					mBizBtn.setImageResource(R.drawable.hidebox);

					mBox.setVisibility(ViewGroup.VISIBLE);
				}
			}
		});
	}

	protected void slideUp(final ViewGroup layout) {
		// TODO Auto-generated method stub
		Animation anim = AnimationUtils.loadAnimation(getActivity(), R.anim.slideup);
		anim.setAnimationListener(new Animation.AnimationListener() {
			@Override
			public void onAnimationStart(Animation animation) {
				// Called when the Animation starts
			}

			@Override
			public void onAnimationEnd(Animation animation) {
				// Called when the Animation ended
				// Since we are fading a View out we set the visibility
				// to GONE once the Animation is finished
				layout.setVisibility(ViewGroup.GONE);
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
				// This is called each time the Animation repeats
			}
		});
		layout.setAnimation(anim);

	}

	protected void slideDown(final ViewGroup layout) {
		// TODO Auto-generated method stub
		Animation anim = AnimationUtils.loadAnimation(getActivity(), R.anim.slidedown);
		anim.setAnimationListener(new Animation.AnimationListener() {
			@Override
			public void onAnimationStart(Animation animation) {
				// Called when the Animation starts
				layout.setVisibility(View.VISIBLE);
			}

			@Override
			public void onAnimationEnd(Animation animation) {
				// Called when the Animation ended
				// Since we are fading a View out we set the visibility
				// to GONE once the Animation is finished

			}

			@Override
			public void onAnimationRepeat(Animation animation) {
				// This is called each time the Animation repeats
			}
		});
		layout.setAnimation(anim);

	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		try {
			super.onActivityResult(requestCode, resultCode, data);
			Bitmap takenPictureData = null;
			String guid = null;
			switch (requestCode) {

			case AppUtil.PICTURE_TAKEN_FROM_CAMERA:
				if (resultCode == Activity.RESULT_OK) {
					takenPictureData = handleResultFromCamera(data);
					guid = cameraFileName;
				}
				break;
			case AppUtil.PICTURE_TAKEN_FROM_GALLERY:
				if (resultCode == Activity.RESULT_OK) {
					takenPictureData = handleResultFromChooser(data);
					guid = cameraFileName;
				}
				break;
			}

			// And show the result in the image view.
			if (takenPictureData != null) {

				ImageView curImage = (ImageView) textEntryViewForResult.findViewById(R.id.contact_image_input);
				curImage.setImageBitmap(takenPictureData);

				curImgFile = takenPictureData;

				textEntryViewForResult.setTag(R.id.tag_third, cameraFileName);
				textEntryViewForResult.setTag(R.id.tag_fourth, cameraFileName);
				textEntryViewForResult.setTag(R.id.tag_sixth, stationId);
				textEntryViewForResult.setTag(R.id.tag_seventh, String.valueOf(takenPictureData.getByteCount()));

			}
		} catch (Exception e) {
			Toast.makeText(getActivity(), getString(R.string.alert_images_error), Toast.LENGTH_LONG).show();
		}
	}

	private Bitmap handleResultFromCamera(Intent data) {
		// TODO Auto-generated method stub

		// get Camera
		Bitmap captureBmp = null;
		try {
			final File file = WidgetUtil.getTempFile(getActivity(), cameraFileName);
			captureBmp = WidgetUtil.adjustImage(Media.getBitmap(getActivity().getContentResolver(), Uri.fromFile(file)));
			WidgetUtil.bitmapToFile(getActivity(), captureBmp, cameraFileName);

			// do whatever you want with the bitmap (Resize, Rename, Add To
			// Gallery, etc)
		} catch (FileNotFoundException e) {
			Toast.makeText(getActivity(), e.toString(), Toast.LENGTH_LONG).show();
		} catch (IOException e) {
			Toast.makeText(getActivity(), e.toString(), Toast.LENGTH_LONG).show();
		} catch (Exception e) {
			Toast.makeText(getActivity(), e.toString(), Toast.LENGTH_LONG).show();
		}

		return captureBmp;

	}

	private Bitmap handleResultFromChooser(Intent data) {
		// TODO Auto-generated method stub

		// get Gallery
		try {
			Uri uriPath = data.getData();
			String[] arrFilePath = { MediaStore.Images.Media.DATA };

			Cursor cursor = getActivity().getContentResolver().query(uriPath, arrFilePath, null, null, null);
			cursor.moveToFirst();

			int columnIndex = cursor.getColumnIndex(arrFilePath[0]);
			String curImgFilePath = cursor.getString(columnIndex);
			cursor.close();

			Bitmap galleryBmp = WidgetUtil.adjustImage(BitmapFactory.decodeFile(curImgFilePath));
			WidgetUtil.bitmapToFile(getActivity(), galleryBmp, cameraFileName);

			return galleryBmp;

		} catch (Exception e) {
			Toast.makeText(getActivity(), getString(R.string.alert_images_error), Toast.LENGTH_LONG).show();
			return null;
		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

		// Inflate the layout for this fragment
		View V = inflater.inflate(R.layout.station_information, container, false);

		return V;

	}

	// TODO: Rename method, update argument and hook method into UI event
	public void onButtonPressed(Uri uri) {
		if (mListener != null) {
			mListener.onFragmentInteraction(uri);
		}
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		((MainActivity) activity).onSectionAttached(getArguments().getInt(AppUtil.ARG_SECTION_NUMBER));
	}

	@Override
	public void onDetach() {
		super.onDetach();
		mListener = null;
	}

	/**
	 * This interface must be implemented by activities that contain this
	 * fragment to allow an interaction in this fragment to be communicated to
	 * the activity and potentially other fragments contained in that activity.
	 * <p>
	 * See the Android Training lesson <a href=
	 * "http://developer.android.com/training/basics/fragments/communicating.html"
	 * >Communicating with Other Fragments</a> for more information.
	 */
	public interface OnFragmentInteractionListener {
		// TODO: Update argument type and name
		public void onFragmentInteraction(Uri uri);
	}

	@Override
	public void processFinish(String method, Object output) {
		// TODO Auto-generated method stub
		try {
			if (method.equals(getString(R.string.method_listzone)))
				search.getListZone(method, output);
			else if (method.equals(getString(R.string.method_liststation)))
				search.getListStation(method, output);
			else if (method.equals(getString(R.string.method_getcustomerinfo)))
				getCustomerInfo(method, output);
			else if (method.equals(getString(R.string.method_getlocationinfo)))
				getLocationInfo(method, output);
			else if (method.equals(getString(R.string.method_getbusinesssupportinfo)))
				getBusinessSupport(method, output);
			else if (method.equals(getString(R.string.method_savecontacts)))
				getSaveContacts(method, output);
			else if (method.equals(getString(R.string.http_url)))
				getSaveImage(method, output);
			else if (method.equals(getString(R.string.method_savesupports)))
				getSaveSupports(method, output);
			else if (method.equals(getString(R.string.method_saveequipmentssqm)))
				getSaveEquipments(method, output);
			else if (method.equals(getString(R.string.method_savebusinesssupportsqm)))
				getSaveBusinessSupport(method, output);
			else if (method.equals(getString(R.string.method_listequipmenttypes)))
				getListEquipmentTypes(method, output);
			else if (method.equals(getString(R.string.method_listbusinesssupporttypes)))
				getListBusinessSupportTypes(method, output);
			else if (method.equals(getString(R.string.method_deletecontactimage)))
				DeleteContactImage(method, output);
		} catch (Exception e) {
		}
	}

	@Override
	public void processFinish(String method, Object output, Object... objects) {
		// TODO Auto-generated method stub
		if (method.startsWith(getString(R.string.img_url)))
			getImage(method, output, objects);
		else if (method.equals(getString(R.string.method_insertcontactimage)))
			getInsertContactImage(method, output, objects);
	}

	private void DeleteContactImage(String method, Object output) {
		// TODO Auto-generated method stub
		onDecrementCount();
		Log.i(method, "Call WS Success");
	}

	private void getBusinessSupport(String method, Object output) {
		// TODO Auto-generated method stub
		WidgetUtil.showProgress(mContentView, mProgressView, false);
		try {
			bizSup = (BusinessSupportInfo) gson.fromJson((String) output, BusinessSupportInfo.class);

			// Show BusinessSupportSQM
			showBusinesses();

			showBusinessMKISs();

			Log.i(method, "Call WS Success");
		} catch (Exception e) {
			Log.i(method, "Call WS Failed");
		}
	}

	private void getLocationInfo(String method, Object output) {
		// TODO Auto-generated method stub
		try {
			locationInfo = (LocationInfo) gson.fromJson((String) output, LocationInfo.class);

			// Show LocationInfo, EquipmentSQM, EquipmentMKIS, InvestInfo
			showLocation();

			showInvest();

			showEquipments();

			showEquipmentMKISs();

			// Call BusinessSupport
			PropertyInfo stationProp = new PropertyInfo();

			stationProp.setName("StationId");
			stationProp.setValue(search.shipToSelected);
			stationProp.setType(String.class);

			mTask = new DefaultTask(com, getString(R.string.method_getbusinesssupportinfo));
			mTask.delegate = fragment;
			mTask.execute(stationProp);

			Log.i(method, "Call WS Success");

			TextView mNoData = (TextView) getView().findViewById(R.id.no_data);
			mNoData.setVisibility(TextView.GONE);
			ViewGroup mHasData = (ViewGroup) getView().findViewById(R.id.has_data);
			mHasData.setVisibility(ViewGroup.VISIBLE);
		} catch (Exception e) {
			Log.i(method, "Call WS Failed");
			WidgetUtil.showProgress(mContentView, mProgressView, false);
			TextView mNoData = (TextView) getView().findViewById(R.id.no_data);
			mNoData.setVisibility(TextView.GONE);
			ViewGroup mHasData = (ViewGroup) getView().findViewById(R.id.has_data);
			mHasData.setVisibility(ViewGroup.VISIBLE);
		}

	}

	private void getCustomerInfo(String method, Object output) {
		// TODO Auto-generated method stub
		try {

			custInfo = (CustomerInfo) gson.fromJson((String) output, CustomerInfo.class);

			stationId = search.shipToSelected;

			// Show CustomerInfo, ContactInfo
			showCustomer();

			showContacts();

			showSuppliers();

			showSupports();

			// Call LocationInfo
			PropertyInfo stationProp = new PropertyInfo();

			stationProp.setName("StationId");
			stationProp.setValue(search.shipToSelected);
			stationProp.setType(String.class);

			PropertyInfo locationProp = new PropertyInfo();

			locationProp.setName("LocationId");
			locationProp.setValue(custInfo.LOCATION_ID);
			locationProp.setType(String.class);

			mTask = new DefaultTask(com, getString(R.string.method_getlocationinfo));
			mTask.delegate = fragment;
			mTask.execute(stationProp, locationProp);

			Log.i(method, "Call WS Success");

		} catch (Exception e) {
			Log.i(method, "Call WS Failed");
			WidgetUtil.showProgress(mContentView, mProgressView, false);

		}

	}

	private void getImage(String method, final Object output, Object... objects) {
		// TODO Auto-generated method stub
		ImageView contactImage = (ImageView) ((TableRow) objects[0]).findViewById(R.id.contact_image_value);
		View mProgressView = ((TableRow) objects[0]).findViewById(R.id.progress);
		WidgetUtil.showProgress(contactImage, mProgressView, false);
		try {

			contactImage.setImageBitmap((Bitmap) output);
			contactImage.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					showImageDialog((Bitmap) output);
				}
			});

			((TableRow) objects[0]).setTag(R.id.tag_seventh, String.valueOf(((Bitmap) output).getByteCount()));

			Log.i(method, "Call WS Success");
		} catch (Exception e) {
			Log.i(method, "Call WS Failed");
		}
	}

	private void getSaveImage(String method, Object output) {
		// TODO Auto-generated method stub
		try {
			Log.i("method", "UploadImage is successful");
		} catch (Exception e) {
			Log.i(method, "Call WS Failed");
		}
	}

	private void getSaveContacts(String method, Object output) {
		// TODO Auto-generated method stub
		onDecrementCount();
		try {

			ContactInfoList contactInfoList = (ContactInfoList) gson.fromJson((String) output, ContactInfoList.class);
			Toast.makeText(getActivity(), AppUtil.toStringWithParam(getString(R.string.alert_save), getString(R.string.contact_tab)), Toast.LENGTH_SHORT).show();

			if (custInfo.ContactInfos != null) {
				custInfo.ContactInfos.set(0, contactInfoList);
			} else {
				custInfo.ContactInfos = new ArrayList<ContactInfoList>();
				custInfo.ContactInfos.add(contactInfoList);
			}

			clearContacts();
			showContacts();

			Log.i(method, "Call WS Success");
		} catch (Exception e) {
			Log.i(method, e.toString());

			custInfo.ContactInfos = null;
			clearContacts();
		}
	}

	private void getSaveSupports(String method, Object output) {
		// TODO Auto-generated method stub
		WidgetUtil.showSubProgress(mSupportView, mProgSupportView, false);
		try {
			SupportInfoList supportInfoList = (SupportInfoList) gson.fromJson((String) output, SupportInfoList.class);
			Toast.makeText(getActivity(), AppUtil.toStringWithParam(getString(R.string.alert_save), getString(R.string.support_tab)), Toast.LENGTH_SHORT).show();

			if (custInfo.SupportInfos != null) {
				custInfo.SupportInfos.set(0, supportInfoList);
			} else {
				custInfo.SupportInfos = new ArrayList<SupportInfoList>();
				custInfo.SupportInfos.add(supportInfoList);
			}

			clearSupports();
			showSupports();

			Log.i(method, "Call WS Success");
		} catch (Exception e) {
			Log.i(method, e.toString());

			custInfo.SupportInfos = null;
			clearSupports();
		}
	}

	private void getSaveBusinessSupport(String method, Object output) {
		// TODO Auto-generated method stub
		WidgetUtil.showSubProgress(mBusinessView, mProgBusinessView, false);
		try {
			BusinessSupportsSQMList businessSupportsSQMList = (BusinessSupportsSQMList) gson.fromJson((String) output, BusinessSupportsSQMList.class);
			Toast.makeText(getActivity(), AppUtil.toStringWithParam(getString(R.string.alert_save), getString(R.string.business_tab)), Toast.LENGTH_SHORT).show();
			if (bizSup.BusinessSupportsSQM != null) {
				bizSup.BusinessSupportsSQM.set(0, businessSupportsSQMList);
			} else {
				bizSup.BusinessSupportsSQM = new ArrayList<BusinessSupportsSQMList>();
				bizSup.BusinessSupportsSQM.add(businessSupportsSQMList);
			}

			clearBusinesses();
			showBusinesses();

			Log.i(method, "Call WS Success");

		} catch (Exception e) {
			Log.i(method, e.toString());
			bizSup.BusinessSupportsSQM = null;
			clearBusinesses();
		}
	}

	private void getSaveEquipments(String method, Object output) {
		// TODO Auto-generated method stub
		WidgetUtil.showSubProgress(mEquipView, mProgEquipView, false);
		try {
			EquipmentsSQMList equipmentsSQMList = (EquipmentsSQMList) gson.fromJson((String) output, EquipmentsSQMList.class);
			Toast.makeText(getActivity(), AppUtil.toStringWithParam(getString(R.string.alert_save), getString(R.string.equipment_tab)), Toast.LENGTH_SHORT).show();

			if (locationInfo.EquipmentsSQM != null) {
				locationInfo.EquipmentsSQM.set(0, equipmentsSQMList);
			} else {
				locationInfo.EquipmentsSQM = new ArrayList<EquipmentsSQMList>();
				locationInfo.EquipmentsSQM.add(equipmentsSQMList);
			}

			clearEquipments();
			showEquipments();

			Log.i(method, "Call WS Success");

		} catch (Exception e) {
			Log.i(method, e.toString());

			locationInfo.EquipmentsSQM = null;
			clearEquipments();
		}
	}

	private void getInsertContactImage(String method, Object output, Object... obj) {
		// TODO Auto-generated method stub
		output = "{" + output + "}";
		try {
			ContactImageResult isSuccess = (ContactImageResult) gson.fromJson((String) output, ContactImageResult.class);
			if (isSuccess.WS_InsertContactImageResult.equals("true")) {
				uploadCall = UploadCall.getInstance();

				PropertyInfo nameProp = new PropertyInfo();
				nameProp.setValue((String) obj[0]);
				nameProp.setType(String.class);

				PropertyInfo bitmapProp = new PropertyInfo();
				bitmapProp.setValue((Bitmap) obj[1]);
				bitmapProp.setType(Bitmap.class);

				mTask = new DefaultTask(uploadCall, getString(R.string.http_url));
				mTask.delegate = fragment;
				mTask.execute(nameProp, bitmapProp);

				Log.i(method, "Call WS Success");
			}

		} catch (Exception e) {
			Log.i(method, e.toString());
		}
	}

	public void getListEquipmentTypes(String method, Object output) {
		// TODO Auto-generated method stub
		try {
			equipmentTypeList = (EquipmentTypeList) gson.fromJson((String) output, EquipmentTypeList.class);
			Log.i(method, "Call WS Success");
		} catch (Exception e) {
			Log.i(method, e.toString());
		}
	}

	public void getListBusinessSupportTypes(String method, Object output) {

		try {
			businessTypeList = (ListBusinessSupportTypesResponse) gson.fromJson((String) output, ListBusinessSupportTypesResponse.class);
			Log.i(method, "Call WS Success");
		} catch (Exception e) {
			Log.i(method, e.toString());
		}

	}

	public void clearSearchStation() {
		search.shipToSelected = "";

		Spinner removeSpin = (Spinner) getActivity().findViewById(R.id.div_assess);
		removeSpin.setSelection(0);

		List<String> removearr = new ArrayList<String>();
		removearr.add(getString(R.string.header_spinner));
		ArrayAdapter<String> removeAdt = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, removearr);

		removeSpin = (Spinner) getActivity().findViewById(R.id.dept_assess);
		removeSpin.setAdapter(removeAdt);

		removeSpin = (Spinner) getActivity().findViewById(R.id.zone_assess);
		removeSpin.setAdapter(removeAdt);

		AutoCompleteTextView autoComplete = (AutoCompleteTextView) getView().findViewById(R.id.station);
		autoComplete.setText("");
	}

	public void clearSearchStationData() {
		clearContacts();
		clearSupports();
		clearSuppliers();
		clearEquipments();
		clearEquipmentMKISs();
		clearBusinesses();
		clearBusinessMKISs();
	}

	// Customer Info
	private void showCustomer() {
		TextView mCustId = (TextView) getView().findViewById(R.id.cust_id);
		TextView mLocId = (TextView) getView().findViewById(R.id.location_id);
		TextView mCustName = (TextView) getView().findViewById(R.id.cust_name);
		TextView mLocName = (TextView) getView().findViewById(R.id.location_name);
		TextView mLocDiv = (TextView) getView().findViewById(R.id.location_div);
		TextView mAddr = (TextView) getView().findViewById(R.id.address);
		TextView mTumbon = (TextView) getView().findViewById(R.id.tumbon);
		TextView mAmphur = (TextView) getView().findViewById(R.id.amphur);
		TextView mProvince = (TextView) getView().findViewById(R.id.province);
		TextView mPostCode = (TextView) getView().findViewById(R.id.postcode);
		TextView mStatusProcess = (TextView) getView().findViewById(R.id.status_process);
		TextView mOpenDate = (TextView) getView().findViewById(R.id.open_date);
		TextView mClosedDate = (TextView) getView().findViewById(R.id.closed_date);

		mCustId.setText(search.shipToSelected);
		mLocId.setText(custInfo.LOCATION_ID);
		mCustName.setText(custInfo.SOLD_TO_NAME);
		mLocName.setText(custInfo.LOCATION_NAME);
		mLocDiv.setText(custInfo.SALES_DISTRICT_DESC);
		mAddr.setText(custInfo.ADDRESS_1);
		mTumbon.setText(custInfo.DISTRICT);
		mAmphur.setText(custInfo.OTHER_CITY);
		mProvince.setText(custInfo.CITY);
		mPostCode.setText(custInfo.POSTAL_CODE);
		mStatusProcess.setText(custInfo.PROCESS_STATUS_DESC);
		mOpenDate.setText(custInfo.DATE_OPEN);
		mClosedDate.setText(custInfo.DATE_CLOSE);
	}

	private void showLocation() {
		TextView mSize = (TextView) getView().findViewById(R.id.local_size);
		TextView mType = (TextView) getView().findViewById(R.id.local_type);
		TextView mStatus = (TextView) getView().findViewById(R.id.local_status);
		TextView mStatusConst = (TextView) getView().findViewById(R.id.local_status_construct);
		TextView mStatusProc = (TextView) getView().findViewById(R.id.local_status_process);
		TextView mAvOwner = (TextView) getView().findViewById(R.id.local_available_owner);
		TextView mOpenDate = (TextView) getView().findViewById(R.id.local_open_date);
		TextView mClosedDate = (TextView) getView().findViewById(R.id.local_closed_date);
		TextView mNgv = (TextView) getView().findViewById(R.id.local_code_ngv);
		TextView mQuality = (TextView) getView().findViewById(R.id.local_code_quality);
		TextView mFuelNozzel = (TextView) getView().findViewById(R.id.local_count_fuel_nozzel);
		TextView mGas91 = (TextView) getView().findViewById(R.id.local_gas91);
		TextView mGas95 = (TextView) getView().findViewById(R.id.local_gas95);
		TextView mE20 = (TextView) getView().findViewById(R.id.local_e20);
		TextView mB5 = (TextView) getView().findViewById(R.id.local_b5);
		TextView mPalm = (TextView) getView().findViewById(R.id.local_palm);

		mSize.setText(custInfo.STATION_SIZE);
		mType.setText(custInfo.FORMAT_DESC);
		mStatus.setText(custInfo.LOC_STATUS);
		mStatusConst.setText(custInfo.CONST_STATUS);
		mStatusProc.setText(custInfo.PROCESS_STATUS_DESC);
		mAvOwner.setText(custInfo.OWNER_STATUS_DESC);
		mOpenDate.setText(custInfo.DATE_OPEN);
		mClosedDate.setText(custInfo.DATE_CLOSE);
		mNgv.setText(custInfo.NGV_STATION_ID);
		mQuality.setText(custInfo.NGV_STATION_ID);
		mFuelNozzel.setText(locationInfo.NOZZLE_QTY);
		mGas91.setText(locationInfo.GASOHOL_91);
		mGas95.setText(locationInfo.GASOHOL_95);
		mE20.setText(locationInfo.GASOHOL_95_E20);
		mB5.setText(locationInfo.HSD_B5);
		mPalm.setText(locationInfo.PALM_DIESEL);
	}

	private void showInvest() {
		TextView mSize = (TextView) getView().findViewById(R.id.invest_size);
		TextView mRai = (TextView) getView().findViewById(R.id.invest_rai);
		TextView mNgan = (TextView) getView().findViewById(R.id.invest_ngan);
		TextView mWidth = (TextView) getView().findViewById(R.id.invest_width);
		TextView mDept = (TextView) getView().findViewById(R.id.invest_dept);

		mSize.setText(locationInfo.InvestmentInfo.get(0).Investment.get(0).STATIONSIZES);
		mRai.setText(locationInfo.InvestmentInfo.get(0).Investment.get(0).STATIONSIZEB);
		mNgan.setText(locationInfo.InvestmentInfo.get(0).Investment.get(0).STATIONSIZEC);
		mWidth.setText(locationInfo.InvestmentInfo.get(0).Investment.get(0).WIDM);
		mDept.setText(locationInfo.InvestmentInfo.get(0).Investment.get(0).LONGM);
	}

	// Contact Info
	private void showContacts() {

		TableLayout table = (TableLayout) getView().findViewById(R.id.contact_table);

		if (custInfo.ContactInfos != null) {
			List<ContactInfo> contactInfoList = custInfo.ContactInfos.get(0).ContactInfo;
			for (int index = 0; index < contactInfoList.size(); index++) {
				ContactInfo contactInfo = contactInfoList.get(index);

				// Add Contact
				TableRow row = showContact(contactInfo);
				table.addView(row);

			}
			table.requestLayout();
		}
	}

	private void clearContacts() {
		TableLayout table = (TableLayout) getView().findViewById(R.id.contact_table);

		// Initialize Header
		if (headerContactRow == null)
			headerContactRow = (TableRow) table.getChildAt(0);

		// Initialize Contacts
		saveContacts = new ArrayList<ContactInfo>();
		deleteContacts = new ArrayList<String>();
		deleteContactImages = new ArrayList<String>();

		table.removeAllViews();

		// Add Header
		table.addView(headerContactRow);

		table.requestLayout();
	}

	private void saveContacts() {
		WidgetUtil.showSubProgress(mContactView, mProgContactView, true);
		TableLayout table = (TableLayout) getView().findViewById(R.id.contact_table);

		for (int index = 1; index < table.getChildCount(); index++) {
			TableRow row = (TableRow) table.getChildAt(index);

			ContactInfo contactInfo = new ContactInfo();
			contactInfo.Idx = ((TextView) row.findViewById(R.id.contact_seq_value)).getText().toString().trim();
			contactInfo.Name = ((TextView) row.findViewById(R.id.contact_fullname_value)).getText().toString().trim();
			contactInfo.Tel = ((TextView) row.findViewById(R.id.contact_tel_value)).getText().toString().trim();
			contactInfo.Mobile = ((TextView) row.findViewById(R.id.contact_mobile_value)).getText().toString().trim();
			contactInfo.Fax = ((TextView) row.findViewById(R.id.contact_fax_value)).getText().toString().trim();
			contactInfo.Email = ((TextView) row.findViewById(R.id.contact_email_value)).getText().toString().trim();
			contactInfo.TransactionId = row.getTag(R.id.tag_second) != null ? (String) row.getTag(R.id.tag_second) : null;
			contactInfo.IsUpdate = false;
			if (!row.getTag(R.id.tag_first).equals(AppUtil.NEW_CONTACT)) {
				contactInfo.RESOURCE_ID = (String) row.getTag(R.id.tag_first);
			}

			if (contactInfo.TransactionId != null) {
				contactInfo.Images.add(new ContactImageList());
				addContactImage(contactInfo.Images.get(0), row);
			}

			if (row.getTag(R.id.tag_first).equals(AppUtil.NEW_CONTACT)) {
				ImageView mImage = (ImageView) row.findViewById(R.id.contact_image_value);
				if (mImage.getDrawable() != null)
					addContactImage((String) row.getTag(R.id.tag_third), ((BitmapDrawable) mImage.getDrawable()).getBitmap());
			}

			saveContacts.add(contactInfo);
		}

		// Call Save Contacts
		PropertyInfo stationProp = new PropertyInfo();
		stationProp.setName("StationId");
		stationProp.setValue(stationId);
		stationProp.setType(String.class);

		PropertyInfo contactsProp = new PropertyInfo();
		contactsProp.setName("Contacts");
		contactsProp.setValue(WebserviceUtil.getContactInfo("Contacts", saveContacts));
		contactsProp.setType(SoapObject.class);

		PropertyInfo DeleteContactsProp = new PropertyInfo();
		DeleteContactsProp.setName("DeleteContactIds");
		DeleteContactsProp.setValue(WebserviceUtil.getString("DeleteContactIds", deleteContacts));
		DeleteContactsProp.setType(SoapObject.class);

		setCount(1 + deleteContactImages.size());

		mTask = new DefaultTask(com, getString(R.string.method_savecontacts));
		mTask.delegate = fragment;
		mTask.execute(stationProp, contactsProp, DeleteContactsProp);

		for (String imageKey : deleteContactImages) {
			deleteImage(imageKey);
		}

	}

	private void addContactImage(String imageKey, Bitmap bitmap) {
		uploadCall = UploadCall.getInstance();

		PropertyInfo nameProp = new PropertyInfo();
		nameProp.setValue((String) imageKey);
		nameProp.setType(String.class);

		PropertyInfo bitmapProp = new PropertyInfo();
		bitmapProp.setValue((Bitmap) bitmap);
		bitmapProp.setType(Bitmap.class);

		mTask = new DefaultTask(uploadCall, getString(R.string.http_url));
		mTask.delegate = fragment;
		mTask.execute(nameProp, bitmapProp);

	}

	private void addContactImage(ContactImageList contactImgs, TableRow row) {
		// TODO Auto-generated method stub
		ContactImage contactImage = new ContactImage();
		contactImage.Station_ID = (String) row.getTag(R.id.tag_sixth);
		contactImage.FILE_SAVE_NAME = (String) row.getTag(R.id.tag_third);
		contactImage.FILE_CONTENT_TYPE = AppUtil.JPG_CONTENT_TYPE;
		contactImage.FILE_SIZE = (String) row.getTag(R.id.tag_seventh);
		contactImage.RESOURCE_TYPENAME = getString(R.string.image_contact);
		contactImage.RESOURCE_DESCRIPTION = AppUtil.EMPTY;
		contactImage.FILE_ORIGINAL_NAME = (String) row.getTag(R.id.tag_fourth);
		contactImage.CreatedDt = (String) row.getTag(R.id.tag_fifth);

		contactImgs.ContactImage.add(contactImage);

	}

	private void deleteImage(String imageKey) {
		// TODO Auto-generated method stub
		PropertyInfo guidProp = new PropertyInfo();
		guidProp.setName(AppUtil.GuidFileName);
		guidProp.setValue(imageKey);
		guidProp.setType(String.class);

		mTask = new DefaultTask(com, getString(R.string.method_deletecontactimage));
		mTask.delegate = this;
		mTask.execute(guidProp);
	}

	private TableRow showContact(ContactInfo contactInfo) {
		TableRow row = (TableRow) LayoutInflater.from(StationInformationFragment.this.getActivity()).inflate(R.layout.contact_row, null);
		((TextView) row.findViewById(R.id.contact_seq_value)).setText(contactInfo.Idx);
		((TextView) row.findViewById(R.id.contact_fullname_value)).setText(contactInfo.Name);
		((TextView) row.findViewById(R.id.contact_tel_value)).setText(contactInfo.Tel);
		((TextView) row.findViewById(R.id.contact_mobile_value)).setText(contactInfo.Mobile);
		((TextView) row.findViewById(R.id.contact_fax_value)).setText(contactInfo.Fax);
		((TextView) row.findViewById(R.id.contact_email_value)).setText(contactInfo.Email);
		row.setTag(R.id.tag_first, contactInfo.RESOURCE_ID);
		row.setTag(R.id.tag_second, contactInfo.TransactionId);

		ImageView contactImage = (ImageView) row.findViewById(R.id.contact_image_value);

		if (contactInfo.TransactionId != null && contactInfo.TransactionId.length() != 0 && contactInfo.Images != null && contactInfo.Images.size() != 0) {
			View mProgressView = row.findViewById(R.id.progress);
			WidgetUtil.showProgress(contactImage, mProgressView, true);

			ContactImage contactImg = contactInfo.Images.get(0).ContactImage.get(0);

			row.setTag(R.id.tag_third, contactImg.FILE_SAVE_NAME);
			row.setTag(R.id.tag_fourth, contactImg.FILE_ORIGINAL_NAME);
			row.setTag(R.id.tag_fifth, contactImg.CreatedDt);
			row.setTag(R.id.tag_sixth, stationId);
			contactImage.setTag(contactImg.FILE_SAVE_NAME);

			if (!DownloadImageOnDevice(contactImage, contactImg.FILE_SAVE_NAME, contactImg.FILE_ORIGINAL_NAME, row)) {
				downloadCall = DownloadCall.getInstance();
				mTask = new DefaultTask(downloadCall, getString(R.string.img_url) + contactImg.FILE_ORIGINAL_NAME, row);
				mTask.delegate = fragment;
				mTask.execute();
			}

		}

		return row;
	}

	// Support Info
	private void clearSupports() {
		TableLayout table = (TableLayout) getView().findViewById(R.id.support_table);

		// Initialize Header
		if (headerSupportRow == null)
			headerSupportRow = (TableRow) table.getChildAt(0);

		// Initialize Contacts
		saveSupports = new ArrayList<SupportInfo>();
		deleteSupports = new ArrayList<String>();

		table.removeAllViews();

		// Add Header
		table.addView(headerSupportRow);

		table.requestLayout();
	}

	private void showSupports() {

		TableLayout table = (TableLayout) getView().findViewById(R.id.support_table);

		if (custInfo.SupportInfos != null) {
			List<SupportInfo> supportInfoList = custInfo.SupportInfos.get(0).SupportInfo;
			for (int index = 0; index < supportInfoList.size(); index++) {
				SupportInfo supportInfo = supportInfoList.get(index);

				// Add Contact
				TableRow row = showSupport(supportInfo);
				table.addView(row);

			}
			table.requestLayout();
		}
	}

	private TableRow showSupport(SupportInfo supportInfo) {
		TableRow row = (TableRow) LayoutInflater.from(StationInformationFragment.this.getActivity()).inflate(R.layout.support_row, null);
		((TextView) row.findViewById(R.id.support_seq_value)).setText(supportInfo.Idx);
		((TextView) row.findViewById(R.id.support_type_value)).setText(supportInfo._TYPE);
		((TextView) row.findViewById(R.id.support_sub_type_value)).setText(supportInfo.SubType);
		((TextView) row.findViewById(R.id.support_collect_value)).setText(supportInfo.NumReceive);
		((TextView) row.findViewById(R.id.support_collect_current_value)).setText(supportInfo.ActaulReceive);
		((TextView) row.findViewById(R.id.support_remark_value)).setText(supportInfo.Remark);
		row.setTag(R.id.tag_first, supportInfo.RESOURCE_ID);

		return row;
	}

	private void saveSupports() {
		WidgetUtil.showSubProgress(mSupportView, mProgSupportView, true);
		TableLayout table = (TableLayout) getView().findViewById(R.id.support_table);

		for (int index = 1; index < table.getChildCount(); index++) {
			TableRow row = (TableRow) table.getChildAt(index);

			SupportInfo supportInfo = new SupportInfo();
			supportInfo.Idx = ((TextView) row.findViewById(R.id.support_seq_value)).getText().toString().trim();
			supportInfo._TYPE = ((TextView) row.findViewById(R.id.support_type_value)).getText().toString().trim();
			supportInfo.SubType = ((TextView) row.findViewById(R.id.support_sub_type_value)).getText().toString().trim();
			supportInfo.NumReceive = ((TextView) row.findViewById(R.id.support_collect_value)).getText().toString().trim();
			supportInfo.ActaulReceive = ((TextView) row.findViewById(R.id.support_collect_current_value)).getText().toString().trim();
			supportInfo.Remark = ((TextView) row.findViewById(R.id.support_remark_value)).getText().toString().trim();
			supportInfo.IsUpdate = false;
			if (!row.getTag(R.id.tag_first).equals(AppUtil.NEW_SUPPORT)) {
				supportInfo.RESOURCE_ID = (String) row.getTag(R.id.tag_first);
			}
			saveSupports.add(supportInfo);
		}

		// Call Save Supports
		PropertyInfo stationProp = new PropertyInfo();
		stationProp.setName("StationId");
		stationProp.setValue(stationId);
		stationProp.setType(String.class);

		PropertyInfo supportsProp = new PropertyInfo();
		supportsProp.setName("Supports");
		supportsProp.setValue(WebserviceUtil.getSupportInfo("Supports", saveSupports));
		supportsProp.setType(SoapObject.class);

		PropertyInfo DeleteContactsProp = new PropertyInfo();
		DeleteContactsProp.setName("DeleteSuppportIds");
		DeleteContactsProp.setValue(WebserviceUtil.getString("DeleteSuppportIds", deleteSupports));
		DeleteContactsProp.setType(SoapObject.class);

		mTask = new DefaultTask(com, getString(R.string.method_savesupports));
		mTask.delegate = fragment;
		mTask.execute(stationProp, supportsProp, DeleteContactsProp);

	}

	// Supplier Info
	private void clearSuppliers() {
		TableLayout table = (TableLayout) getView().findViewById(R.id.supplier_table);

		// Initialize Header
		if (headerSupplierRow == null)
			headerSupplierRow = (TableRow) table.getChildAt(0);

		table.removeAllViews();

		// Add Header
		table.addView(headerSupplierRow);

		table.requestLayout();
	}

	private void showSuppliers() {

		TableLayout table = (TableLayout) getView().findViewById(R.id.supplier_table);

		if (custInfo.SupplierInfos != null) {
			List<SupplierInfo> supplierInfoList = custInfo.SupplierInfos.get(0).SupplierInfo;
			for (int index = 0; index < supplierInfoList.size(); index++) {
				SupplierInfo supplierInfo = supplierInfoList.get(index);

				// Add Contact
				TableRow row = showSupplier(supplierInfo);
				table.addView(row);

			}
			table.requestLayout();
		}
	}

	private TableRow showSupplier(SupplierInfo supplierInfo) {
		TableRow row = (TableRow) LayoutInflater.from(StationInformationFragment.this.getActivity()).inflate(R.layout.supplier_row, null);
		((TextView) row.findViewById(R.id.supplier_code_value)).setText(supplierInfo.Code);
		((TextView) row.findViewById(R.id.supplier_name_value)).setText(supplierInfo.FullName);
		((TextView) row.findViewById(R.id.supplier_dept_value)).setText(supplierInfo.Section);

		return row;
	}

	// Equipment SQM Info
	private void clearEquipments() {
		TableLayout table = (TableLayout) getView().findViewById(R.id.equipmentsqm_table);

		// Initialize Header
		if (headerEquipmentRow == null)
			headerEquipmentRow = (TableRow) table.getChildAt(0);

		// Initialize Contacts
		saveEquipments = new ArrayList<EquipmentSQM>();
		deleteEquipments = new ArrayList<String>();

		table.removeAllViews();

		// Add Header
		table.addView(headerEquipmentRow);

		table.requestLayout();
	}

	private void showEquipments() {

		TableLayout table = (TableLayout) getView().findViewById(R.id.equipmentsqm_table);

		if (locationInfo.EquipmentsSQM != null) {
			List<EquipmentSQM> equipmentList = locationInfo.EquipmentsSQM.get(0).EquipmentSQM;
			for (int index = 0; index < equipmentList.size(); index++) {
				EquipmentSQM equipment = equipmentList.get(index);

				// Add Contact
				TableRow row = showEquipment(equipment);
				table.addView(row);

			}
			table.requestLayout();
		}
	}

	private TableRow showEquipment(EquipmentSQM equipment) {
		TableRow row = (TableRow) LayoutInflater.from(StationInformationFragment.this.getActivity()).inflate(R.layout.equipment_row, null);
		((TextView) row.findViewById(R.id.equipment_seq_value)).setText(equipment.IDX);
		((TextView) row.findViewById(R.id.equipment_type_value)).setText(equipment.EQUIPTYPE);
		((TextView) row.findViewById(R.id.equipment_brand_value)).setText(equipment.BRAND);
		((TextView) row.findViewById(R.id.equipment_gen_value)).setText(equipment.MODEL);
		((TextView) row.findViewById(R.id.equipment_sn_value)).setText(equipment.SN);
		((TextView) row.findViewById(R.id.equipment_code_value)).setText(equipment.EQUIPCODE);
		((TextView) row.findViewById(R.id.equipment_price_value)).setText(equipment.VALUE);
		((TextView) row.findViewById(R.id.equipment_amount_ma_value)).setText(equipment.NUM);
		((TextView) row.findViewById(R.id.equipment_price_ma_value)).setText(equipment.COST);
		((TextView) row.findViewById(R.id.equipment_category_value)).setText(equipment.EQUIPEMENTTYPE);
		row.setTag(R.id.tag_first, equipment.RESOURCE_ID);
		row.setTag(R.id.tag_second, equipment.EQUIPEMENTTYPE_ID);
		return row;
	}

	private void saveEquipments() {
		WidgetUtil.showSubProgress(mEquipView, mProgEquipView, true);
		TableLayout table = (TableLayout) getView().findViewById(R.id.equipmentsqm_table);

		for (int index = 1; index < table.getChildCount(); index++) {
			TableRow row = (TableRow) table.getChildAt(index);

			EquipmentSQM equipment = new EquipmentSQM();
			equipment.IDX = ((TextView) row.findViewById(R.id.equipment_seq_value)).getText().toString().trim();
			equipment.EQUIPTYPE = ((TextView) row.findViewById(R.id.equipment_type_value)).getText().toString().trim();
			equipment.BRAND = ((TextView) row.findViewById(R.id.equipment_brand_value)).getText().toString().trim();
			equipment.MODEL = ((TextView) row.findViewById(R.id.equipment_gen_value)).getText().toString().trim();
			equipment.SN = ((TextView) row.findViewById(R.id.equipment_sn_value)).getText().toString().trim();
			equipment.EQUIPCODE = ((TextView) row.findViewById(R.id.equipment_code_value)).getText().toString().trim();
			equipment.VALUE = ((TextView) row.findViewById(R.id.equipment_price_value)).getText().toString().trim();
			equipment.NUM = ((TextView) row.findViewById(R.id.equipment_amount_ma_value)).getText().toString().trim();
			equipment.COST = ((TextView) row.findViewById(R.id.equipment_price_ma_value)).getText().toString().trim();
			equipment.EQUIPEMENTTYPE = ((TextView) row.findViewById(R.id.equipment_category_value)).getText().toString().trim();
			equipment.EQUIPEMENTTYPE_ID = (String) row.getTag(R.id.tag_second);
			equipment.IsUpdate = false;
			if (!row.getTag(R.id.tag_first).equals(AppUtil.NEW_EQUIPMENTSQM)) {
				equipment.RESOURCE_ID = (String) row.getTag(R.id.tag_first);
			}
			saveEquipments.add(equipment);
		}

		// Call Save Supports
		PropertyInfo stationProp = new PropertyInfo();
		stationProp.setName("StationId");
		stationProp.setValue(stationId);
		stationProp.setType(String.class);

		PropertyInfo equipmentProp = new PropertyInfo();
		equipmentProp.setName("EquipmentsSQM");
		equipmentProp.setValue(WebserviceUtil.getEquipmentSQM("EquipmentsSQM", saveEquipments));
		equipmentProp.setType(SoapObject.class);

		PropertyInfo DeleteEquipmentsProp = new PropertyInfo();
		DeleteEquipmentsProp.setName("DeleteEquipmentSQMIds");
		DeleteEquipmentsProp.setValue(WebserviceUtil.getString("DeleteEquipmentSQMIds", deleteEquipments));
		DeleteEquipmentsProp.setType(SoapObject.class);

		mTask = new DefaultTask(com, getString(R.string.method_saveequipmentssqm));
		mTask.delegate = fragment;
		mTask.execute(stationProp, equipmentProp, DeleteEquipmentsProp);

	}

	// Equipment MKIS Info
	private void clearEquipmentMKISs() {
		TableLayout table = (TableLayout) getView().findViewById(R.id.equipmentmkis_table);

		// Initialize Header
		if (headerEquipmentMKISRow == null)
			headerEquipmentMKISRow = (TableRow) table.getChildAt(0);

		table.removeAllViews();

		// Add Header
		table.addView(headerEquipmentMKISRow);

		table.requestLayout();
	}

	private void showEquipmentMKISs() {

		TableLayout table = (TableLayout) getView().findViewById(R.id.equipmentmkis_table);

		if (locationInfo.EquipmentsMKIS != null) {
			List<EquipmentMKIS> equipmentList = locationInfo.EquipmentsMKIS.get(0).EquipmentMKIS;
			for (int index = 0; index < equipmentList.size(); index++) {
				EquipmentMKIS equipment = equipmentList.get(index);

				// Add Contact
				TableRow row = showEquipmentMKIS(equipment);
				table.addView(row);

			}
			table.requestLayout();
		}
	}

	private TableRow showEquipmentMKIS(EquipmentMKIS equipment) {
		TableRow row = (TableRow) LayoutInflater.from(StationInformationFragment.this.getActivity()).inflate(R.layout.equipmentmkis_row, null);
		((TextView) row.findViewById(R.id.equipment_type_value)).setText(equipment.EQUIPTYPE);
		((TextView) row.findViewById(R.id.equipment_brand_value)).setText(equipment.BRAND);
		((TextView) row.findViewById(R.id.equipment_gen_value)).setText(equipment.MODEL);
		((TextView) row.findViewById(R.id.equipment_sn_value)).setText(equipment.SN);
		((TextView) row.findViewById(R.id.equipment_code_value)).setText(equipment.EQUIPCODE);
		((TextView) row.findViewById(R.id.equipment_price_value)).setText(equipment.VALUE);
		((TextView) row.findViewById(R.id.equipment_amount_ma_value)).setText(equipment.NUM);
		((TextView) row.findViewById(R.id.equipment_price_ma_value)).setText(equipment.COS);

		return row;
	}

	// BusinessSQM Info
	private void clearBusinesses() {
		TableLayout table = (TableLayout) getView().findViewById(R.id.businesssqm_table);

		// Initialize Header
		if (headerBusinessRow == null)
			headerBusinessRow = (TableRow) table.getChildAt(0);

		// Initialize Contacts
		saveBusiness = new ArrayList<BusinessSupportSQM>();
		deleteBusiness = new ArrayList<String>();

		table.removeAllViews();

		// Add Header
		table.addView(headerBusinessRow);

		table.requestLayout();
	}

	private void showBusinesses() {

		TableLayout table = (TableLayout) getView().findViewById(R.id.businesssqm_table);

		if (bizSup.BusinessSupportsSQM != null) {
			List<BusinessSupportSQM> businessList = bizSup.BusinessSupportsSQM.get(0).BusinessSupportSQM;
			for (int index = 0; index < businessList.size(); index++) {
				BusinessSupportSQM business = businessList.get(index);

				// Add Contact
				TableRow row = showBusiness(business);
				table.addView(row);

			}
			table.requestLayout();
		}
	}

	private TableRow showBusiness(BusinessSupportSQM business) {
		TableRow row = (TableRow) LayoutInflater.from(StationInformationFragment.this.getActivity()).inflate(R.layout.business_row, null);
		((TextView) row.findViewById(R.id.business_seq_value)).setText(business.IDX);
		((TextView) row.findViewById(R.id.business_type_value)).setText(business.BUSTYPE);
		((TextView) row.findViewById(R.id.business_name_value)).setText(business.SUPPORTNAME);
		((TextView) row.findViewById(R.id.business_custname_value)).setText(business.CUSNAME);
		((TextView) row.findViewById(R.id.business_status_value)).setText(business.STATUS);

		row.setTag(R.id.tag_first, business.RESOURCE_ID);

		return row;
	}

	private void saveBusinesses() {
		WidgetUtil.showSubProgress(mBusinessView, mProgBusinessView, true);
		TableLayout table = (TableLayout) getView().findViewById(R.id.businesssqm_table);

		for (int index = 1; index < table.getChildCount(); index++) {
			TableRow row = (TableRow) table.getChildAt(index);

			BusinessSupportSQM business = new BusinessSupportSQM();
			business.IDX = ((TextView) row.findViewById(R.id.business_seq_value)).getText().toString().trim();
			business.BUSTYPE = ((TextView) row.findViewById(R.id.business_type_value)).getText().toString().trim();
			business.SUPPORTNAME = ((TextView) row.findViewById(R.id.business_name_value)).getText().toString().trim();
			business.CUSNAME = ((TextView) row.findViewById(R.id.business_custname_value)).getText().toString().trim();
			business.STATUS = ((TextView) row.findViewById(R.id.business_status_value)).getText().toString().trim();
			business.IsUpdate = false;
			if (!row.getTag(R.id.tag_first).equals(AppUtil.NEW_BUSINESS)) {
				business.RESOURCE_ID = (String) row.getTag(R.id.tag_first);
			}

			saveBusiness.add(business);
		}

		// Call Save Supports
		PropertyInfo stationProp = new PropertyInfo();
		stationProp.setName("StationId");
		stationProp.setValue(stationId);
		stationProp.setType(String.class);

		PropertyInfo supportsProp = new PropertyInfo();
		supportsProp.setName("BusinessSupportsSQM");
		supportsProp.setValue(WebserviceUtil.getBusinessSQM("BusinessSupportsSQM", saveBusiness));
		supportsProp.setType(SoapObject.class);

		PropertyInfo DeleteBussinessProp = new PropertyInfo();
		DeleteBussinessProp.setName("BusinessSupportSQMIds");
		DeleteBussinessProp.setValue(WebserviceUtil.getString("BusinessSupportSQMIds", deleteBusiness));
		DeleteBussinessProp.setType(SoapObject.class);

		mTask = new DefaultTask(com, getString(R.string.method_savebusinesssupportsqm));
		mTask.delegate = fragment;
		mTask.execute(stationProp, supportsProp, DeleteBussinessProp);

	}

	// BusinessMKIS Info
	private void clearBusinessMKISs() {
		TableLayout table = (TableLayout) getView().findViewById(R.id.businessmkis_table);

		// Initialize Header
		if (headerBusinessMKISRow == null)
			headerBusinessMKISRow = (TableRow) table.getChildAt(0);

		table.removeAllViews();

		// Add Header
		table.addView(headerBusinessMKISRow);

		table.requestLayout();
	}

	private void showBusinessMKISs() {

		TableLayout table = (TableLayout) getView().findViewById(R.id.businessmkis_table);

		if (bizSup.BusinessSupportsMKIS != null) {
			List<BusinessSupportMKIS> businessList = bizSup.BusinessSupportsMKIS.get(0).BusinessSupportMKIS;
			for (int index = 0; index < businessList.size(); index++) {
				BusinessSupportMKIS business = businessList.get(index);

				// Add Contact
				TableRow row = showBusinessMKIS(business);
				table.addView(row);

			}
			table.requestLayout();
		}
	}

	private TableRow showBusinessMKIS(BusinessSupportMKIS business) {
		TableRow row = (TableRow) LayoutInflater.from(StationInformationFragment.this.getActivity()).inflate(R.layout.businessmkis_row, null);
		((TextView) row.findViewById(R.id.business_type_value)).setText(business.BUSTYPE);
		((TextView) row.findViewById(R.id.business_name_value)).setText(business.SUPPORTNAME);
		((TextView) row.findViewById(R.id.business_custname_value)).setText(business.CUSNAME);
		((TextView) row.findViewById(R.id.business_status_value)).setText(business.STATUS);

		return row;
	}

	public boolean isValid() {
		// TODO Auto-generated method stub
		boolean flag = true;

		AutoCompleteTextView stationAuto = (AutoCompleteTextView) getView().findViewById(R.id.station);

		TextView stationAlert = (TextView) getView().findViewById(R.id.station_alert);

		if (search.shipToSelected == null || search.shipToSelected.length() == 0) {
			stationAlert.setError(getString(R.string.alert_required_field));
			stationAlert.requestFocus();
			flag = false;
		} else {
			stationAlert.setError(null);
		}

		return flag;
	}

	private void showImageDialog(Bitmap bitmap) {
		// TODO Auto-generated method stub
		AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
		LayoutInflater factory = LayoutInflater.from(getActivity());
		View imageEntryView = factory.inflate(R.layout.image_slider, null);
		alert.setView(imageEntryView);

		final AlertDialog dialog = alert.create();

		((ImageView) imageEntryView.findViewById(R.id.takeashot)).setVisibility(ImageView.INVISIBLE);
		((ImageView) imageEntryView.findViewById(R.id.trash)).setVisibility(ImageView.INVISIBLE);

		List<Bitmap> bitmaps = new ArrayList<Bitmap>();
		bitmaps.add(bitmap);

		ViewPager viewPager = (ViewPager) imageEntryView.findViewById(R.id.view_pager);
		ImageAdapter adapter = new ImageAdapter(getActivity(), bitmaps);
		viewPager.setAdapter(adapter);
		dialog.show();
	}

	private boolean DownloadImageOnDevice(ImageView contactImage, String filename, String origfilename, TableRow row) {
		// TODO Auto-generated method stub
		View mProgressView = row.findViewById(R.id.progress);
		WidgetUtil.showProgress(contactImage, mProgressView, false);
		try {

			final Bitmap output = WidgetUtil.getImageOnDevice(getActivity(), origfilename);
			if (output != null) {
				contactImage.setImageBitmap(output);
				contactImage.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						showImageDialog(output);
					}
				});

				row.setTag(R.id.tag_seventh, String.valueOf(output.getByteCount()));

				return true;
			}
		} catch (Exception e) {

		}
		return false;
	}

	public void listBusinessSupportTypes(View view) {

		List<String> arr = new ArrayList<String>();
		for (int index = 0; index < businessTypeList.BusinessSupportTypeResult.size(); index++) {
			arr.add(businessTypeList.BusinessSupportTypeResult.get(index).BUSTYPE);
		}

		ArrayAdapter<String> arrAdt = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, arr);

		final AutoCompleteTextView autoComplete = (AutoCompleteTextView) view.findViewById(R.id.business_type_input);
		autoComplete.setAdapter(arrAdt);
		autoComplete.setThreshold(1);

		autoComplete.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				// TODO Auto-generated method stub
				// shipToSelected = arg0.getItemAtPosition(arg2);
			}
		});

		autoComplete.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View arg0, MotionEvent arg1) {
				// TODO Auto-generated method stub
				if (autoComplete.getText().toString().length() == 0) {
					autoComplete.showDropDown();
				}

				return false;
			}
		});

		autoComplete.setOnKeyListener(new OnKeyListener() {

			@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				// TODO Auto-generated method stub

				if (autoComplete.getText().toString().length() == 0)
					autoComplete.showDropDown();
				return false;
			}

		});
	}

	@Override
	public void setCount(int cnt) {
		this.cnt = cnt;
	}

	@Override
	public void onDecrementCount() {
		cnt--;
		if (cnt <= 0) {
			WidgetUtil.showSubProgress(mContactView, mProgContactView, false);
		}
	}

	@Override
	public void onDecrementCount(View view, int cnt) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onDecrementCount(boolean flag) {
		// TODO Auto-generated method stub

	}
}
